// import { map } from "lodash"

export default function (Vue, options) {
  Vue.mixin({
    data() {
      if (this.$options === undefined || this.$options.dictParams === undefined || this.$options.dictParams === null) {
        return {}
      }
      return {
        dict: {}
      }
    },
    async onLoad() {
       if(!this.dict){
         return
       }
      var dictParams = this.$options.dictParams
      if (dictParams) {
        let paramsMap = new Map()
        dictParams.forEach(item=>{
          paramsMap.set(item, [])
        }) 

         Vue.set(this,'dict',Object.fromEntries(paramsMap))
        const res = await this.$getDict(dictParams.join())
        //处理数据类型
        for(let item in res.data){
          let data = res.data[item];
          for(let i =0; i< data.length; i++){
            if(!isNaN(parseInt(data[i].dictKey))){
              data[i].dictKey = parseInt(data[i].dictKey)
            }
              
          }
        }
        this.dict = res.data
        Vue.set(this,'dict',res.data)
        this.$nextTick(() => {
          if (this.$options && this.$options.onDictReady instanceof Function) {
            this.$options.onDictReady.call(this, res.data)
          }
        })
      }
    }
  })
}
